package cn.hd.service.impl;

import cn.hd.dao.AddressDao;
import cn.hd.entity.Address;
import cn.hd.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;

    @Override
    public int addAddress(Address address) {
        return addressDao.addAddress(address);
    }
    @Override
    public int addUserAddressUser(long uid, long aid) {
        return addressDao.addUserAddressUser(uid,aid);
    }

    @Override
    public int deleteAddress(long aid) {
        return addressDao.deleteAddress(aid);
    }

    @Override
    public int deleteAddressUser(long aid,long uid) {
        return addressDao.deleteAddressUser(aid,uid);
    }

    @Override
    public int updateAddress(Address address) {
        return addressDao.updateAddress(address);
    }

    @Override
    public List<Address> selectuidAddress(long uid) {
        List<Address> addresses = addressDao.selectuidAddress(uid);
        for (Address a : addresses){
            a.setAddress(a.getAddress().replace(",",""));
        }
        return addressDao.selectuidAddress(uid);
    }

    @Override
    public Address selectByAid(long aid) {
        Address address = addressDao.selectByAid(aid);
        String[] ads = address.getAddress().split(",");
        address.setAds(ads);
        return address;
    }

    @Override
    public Address selectByBid(long bid) {
        return addressDao.selectByBid(bid);
    }

}
